import axios from 'axios'
import type { Yuyue } from '@/types/yuyue'

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080'

export const addYuyue = (yuyue: Yuyue) => {
  return axios.post(`${API_BASE_URL}/yuyue/add`, yuyue)
}

export const cancelYuyue = (id: number) => {
  return axios.get(`${API_BASE_URL}/yuyue/cancel?id=${id}`)
}

export const getYuyueList = (status?: number) => {
  const params = status !== undefined ? { status } : {}
  return axios.get(`${API_BASE_URL}/yuyue/list`, { params })
}

export const getYuyueByCheliangId = (cheliangId: number) => {
  return axios.get(`${API_BASE_URL}/yuyue/byCheliang?cheliangId=${cheliangId}`)
}

export const getYuyueByUserId = (userId: number) => {
  return axios.get(`${API_BASE_URL}/yuyue/byUser?userId=${userId}`)
}

export const approveYuyue = (id: number) => {
  return axios.get(`${API_BASE_URL}/yuyue/approve?id=${id}`)
}

export const rejectYuyue = (id: number) => {
  return axios.get(`${API_BASE_URL}/yuyue/reject?id=${id}`)
}
